import getEnvConfig from "@/config/axios/getEnvConfig";

let modeControl = {
  mounted(el, binding) {
    //当前设备生产是什么模式 test--调试模式 product--正常生产
    //['test','product']
    let mode = getEnvConfig.VITE_PRODUCT_MODE;
    let allowEnv = [];
    if (binding.value === "all") return;

    if (typeof binding.value == "string") {
      allowEnv = [binding.value];
    } else if (Array.isArray(binding.value)) {
      allowEnv = [...binding.value];
    }
    if (allowEnv.includes("-r")) {
      allowEnv.includes(mode) && remove(el);
    } else {
      !allowEnv.includes(mode) && remove(el);
    }
  },
};

function remove(el) {
  if (el.parentNode) {
    el.parentNode.removeChild(el);
  } else {
    el.style.display = "none";
  }
}

export default modeControl;
